;!(function ($)
{
    $.fn.setFormValue = function (options)
    {
        var $this = $(this);

        $.each(options, function (key, value)
        {
            var obj = $this.find("*[name=" + key + "]");

            if (obj.attr("type") == "checkbox")
            {
                if ($.type(value) === "boolean")
                {
                    obj.attr("checked", value);
                }

                if ($.type(value) === "object")
                {
                    $.each(value, function (i, item)
                    {
                        $this.find("*[name=" + key + "][value=" + i + "]").attr("checked", item);
                    })
                }
            }
            else if (obj.attr("type") == "radio")
            {
                $this.find("*[name=" + key + "][value=" + value + "]").attr("checked", true);
            }
            else
            {
                obj.val(value);
            }
        })
    }

})(jQuery)
;
function formatDate(datetime) {
    var date = new Date(datetime);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var year = date.getFullYear(),
        month = ("0" + (date.getMonth() + 1)).slice(-2),
        sdate = ("0" + date.getDate()).slice(-2),
        hour = ("0" + date.getHours()).slice(-2),
        minute = ("0" + date.getMinutes()).slice(-2),
        second = ("0" + date.getSeconds()).slice(-2);
    // 拼接
    var result = year + "-"+ month +"-"+ sdate +" "+ hour +":"+ minute +":" + second;
    // 返回
    return result;
}

/**
 * 上传图片
 * @param url
 * @param data
 * @param callback 上传成功后要做的事情
 */
function uploadFile(url,data,callback){
    $.ajax({
        data:data,
        type:"post",
        url:url,
        cache:false,
        contentType:false,
        processData:false,
        success:function (res){
            if (res.code === 0){
                callback(res)
            }
            else{
                alert(res.data)
            }
        },
        error:function (res){
            alert("上传失败:请到控制台查看详情")
            console.log(res)
        }
    })
}

/**
 * 获取File的URL对象
 * @param eleId
 * @returns {string}
 */
function getFileUrl(eleId){
    var url;

    //获取file对象URL
    if (navigator.userAgent.indexOf("MSIE") >= 1) { // IE
        url = document.getElementById(eleId).value;
    } else if (navigator.userAgent.indexOf("Firefox") > 0) { // Firefox
        url = window.URL.createObjectURL(document.getElementById(eleId).files.item(0));
    } else if (navigator.userAgent.indexOf("Chrome") > 0) { // Chrome
        url = window.URL.createObjectURL(document.getElementById(eleId).files[0]);
    }
    return url;
}

